package com.passive.lock.service.log.imp;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.passive.lock.mapper.TSysLogMapper;
import com.passive.lock.mapper.TSysLogMapperCustom;
import com.passive.lock.model.po.TSysLog;
import com.passive.lock.model.vo.TLockVo;
import com.passive.lock.model.vo.TSysLogVo;
import com.passive.lock.service.log.SysLogService;
import com.passive.lock.utils.Config;
import com.passive.lock.utils.DateUtils;
import com.passive.lock.utils.ResourcesUtil;

@Service("sysLogService")
public class SysLogServiceImpl implements SysLogService {
	@Resource(name = "TSysLogMapper")
	private TSysLogMapper tSysLogMapper;
	
	@Resource(name = "TSysLogMapperCustom")
	private TSysLogMapperCustom sysLogMapperCustom;

	@Override
	public int addSysLog(String key, Integer userid, String ids, String username, String logtype, String groupid,
			Integer count) {

		String logresult = ResourcesUtil.getValue(Config.MESSAGE, key, new Object[] { username, count, ids });
		TSysLog sysLog = new TSysLog();
		sysLog.setLogtype(logtype);
		sysLog.setLogtime(System.currentTimeMillis());
		sysLog.setLogresult(logresult);
		sysLog.setUserid(userid);
		sysLog.setGroupid(groupid);
		int res = tSysLogMapper.insert(sysLog);
		return res;
	}

	@Override
	public List<TSysLogVo> sysLogList(String groupid, long beginTime, long endTime, String logType, String username,
			int offset, Integer limit) throws Exception {
		List<TSysLogVo> list= sysLogMapperCustom.sysLogList(beginTime, endTime, groupid, logType, username, offset, limit);
		for (TSysLogVo tSysLogVo : list) {
			tSysLogVo.setSyslogtime(DateUtils.unixTimestampToDate(tSysLogVo.getLogtime()));
		}
		return list;
	}


	@Override
	public int sysLogListCount(String groupid, long beginTime, long endTime, String logType, String username) throws Exception{
		
		int count= sysLogMapperCustom.sysLogListCount(beginTime, endTime, groupid, logType, username);
		return count;
	}

}
